package com.example.invalidatetest;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.util.Log;

public class PathGenerator {
	
	
	public synchronized Path generator(int[][] coords){
		
		Path p1 = new Path();
		int x_offset = OffsetConstant.offset_x;
		int y_offset = OffsetConstant.offset_y;
		

		p1.moveTo( (coords[0][0]-x_offset), (-(coords[0][1]-y_offset))   );
				
		for(int i = 1; i<coords.length;i++){
			p1.lineTo(  (coords[i][0]-x_offset),  (-(coords[i][1]-y_offset))  );
			
								
			Log.d("COORD", + ((coords[i][0]))  + " " + ((coords[i][1])));
			
			Log.d("Difference","X difference " + (coords[i-1][0]-coords[i][0]));
			Log.d("Difference","Y difference " + (coords[i-1][1]-coords[i][1]));
			
			}
		//p1.setLastPoint(coords[coords.length-1][0], coords[coords.length-1][1]);
		
		
		Log.d("GENERATOR", "Genetator ok");
		return p1;
		
		
		
	}
	
	
	public static synchronized PathCombinedColour PCCgenerator(int[][] coords){
		
		Path p1 = new Path();
		Paint paint =  new Paint(Paint.ANTI_ALIAS_FLAG);
		int x_offset = OffsetConstant.offset_x;
		int y_offset = OffsetConstant.offset_y;
		PathCombinedColour pccComplete;
		

		p1.moveTo( (coords[0][0]-x_offset), (-(coords[0][1]-y_offset))   );
				
		for(int i = 1; i<coords.length;i++){
			p1.lineTo(  (coords[i][0]-x_offset),  (-(coords[i][1]-y_offset))  );
			
								
			Log.d("COORD", + ((coords[i][0]))  + " " + ((coords[i][1])));
			
			Log.d("Difference","X difference " + (coords[i-1][0]-coords[i][0]));
			Log.d("Difference","Y difference " + (coords[i-1][1]-coords[i][1]));
			Log.d("OFFSET", OffsetConstant.offset_x+"x " + OffsetConstant.offset_y+" y");
			
			}
		//p1.setLastPoint(coords[coords.length-1][0], coords[coords.length-1][1]);
		
		
		Log.d("GENERATOR", "PCC Genetator ok");
		
		
		//IF start and end points differ loop is open
		if((coords[0][0] != coords[coords.length-1][0]) ||(coords[0][1] != coords[coords.length-1][1]) ){
			paint.setStyle(Style.STROKE);
			paint.setStrokeWidth(6);
			paint.setColor(ColorConstants.openWay);}
		
		else{paint.setColor(ColorConstants.ClosedWay);
			Log.d("loop", "loop is closed");}
		
		pccComplete = new PathCombinedColour(p1,paint);
		
		
		return pccComplete;
		
		
		
	}

}
